package net.lee.algorithm.linkedorder;

public class DoubleLinkOrder {

    public static void main(String args[])
    {
        DoubleLinkObject linkObject1 = new DoubleLinkObject();
        linkObject1.setValue(1);
        DoubleLinkObject linkObject2 = new DoubleLinkObject();
        linkObject2.setValue(2);
        linkObject1.setNextObject(linkObject2);
        linkObject2.setPreObject(linkObject1);
        DoubleLinkObject linkObject3 = new DoubleLinkObject();
        linkObject3.setValue(3);
        linkObject3.setPreObject(linkObject2);
        linkObject2.setNextObject(linkObject3);

        DoubleLinkObject linkObject =linkObject1;
        while (linkObject!=null) {
            DoubleLinkObject tempObject = linkObject.getNextObject();
            linkObject.setNextObject(linkObject.getPreObject());
            linkObject.setPreObject(tempObject);

            if(tempObject!=null)
            {
                linkObject = tempObject;
            }else
            {
                break;
            }


        }
        while (linkObject!=null)
        {
            System.out.print(linkObject.getValue()+"-");
            linkObject =linkObject.getNextObject();
        }
    }
}
